package com.zhilifang.modules.zlf.controller;

import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhilifang.modules.zlf.entity.Banner;
import com.zhilifang.modules.zlf.service.impl.BannerServiceImpl;
import com.zhilifang.modules.zlf.utils.Result;

/**
 * Controller 后台首页>>形象管理Controller
 */
@Controller
@RequestMapping("/bannerController")
public class BannerController {

	@Autowired
	private BannerServiceImpl bannerServiceImpl ;
	
	
	/**
	 * Banner列表加载
	 * 
	 * @return
	 */
	@RequestMapping(value = "/selectBannerListrAll", method = RequestMethod.POST)
	@ResponseBody
	public List<Banner> selectBannerListrAll(){
		List<Banner> list = bannerServiceImpl.selectBannerListrAll();	
		return list;
	}
	
	

	/**
	 * 添加&&修改
	 * 
	 * @return
	 */
	@RequestMapping(value = "/insertUpdateBanner", method = RequestMethod.POST)
	@ResponseBody
	public Result insertUpdateBanner(Banner banner){
		Result result = new Result();
		if(banner.getId()!=null){
			bannerServiceImpl.updateBanner(banner);
			result.setMessage("修改成功");
			result.setState("200");
		}else{
			bannerServiceImpl.insertBanner(banner);
			result.setData(banner.getId());  //返回新增的id
			result.setMessage("添加成功");
			result.setState("200");
		}
		
		return result;
	}
	
	
	
	/**
	 * 删除产品类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "/deleteBanner", method = RequestMethod.POST)
	@ResponseBody
	public Result deleteBanner(int id){
		Result result = new Result();
		bannerServiceImpl.deleteBanner(id);
		result.setState("200");
		result.setMessage("删除成功");
		return result;
	}
	
}
